Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

[vpp] Enable copy pass thru for VAAPI #1268

Merged

Conversation

Alexandr-Konovalov
Copy link
Contributor

Issue: MDP-53850
Fixes: #1027

@@ -908,6 +908,8 @@ namespace MfxHwVideoProcessing
mfxFrameSurface1 *pInputSurface,
mfxFrameSurface1 *pOutputSurface);

mfxStatus IsCopyPassThroughPreferred(bool &preferred) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This design looks ugly, this function should simply return bool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this function:). Both prototype (+1 to @mgonchar) and how it named/what it does. It returns not deterministic result: "I check copy pass thru, maybe I like it maybe not - decide later". I would like to see function named useSOMETHING() with the obvious inclination.

To be honest, I got lost in CopyPassThrough name. What it actually mean? Copy with memcpy or CM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to say something like "performance of CopyPassThrough is good, you want to use it" vs "it's better to omit CopyPassThrough" and to hide low-level details what is used inside and what is faster.

@@ -3115,9 +3134,16 @@ mfxStatus VideoVPPHW::VppFrameCheck(
#endif
MFX_CHECK_STS(sts);

bool useCopyPassThrough = false;
if (true == m_config.m_bCopyPassThroughEnable && false == IsRoiDifferent(pTask->input.pSurf, pTask->output.pSurf))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like bool to bool conversions.
As for me

if (m_config.m_bCopyPassThroughEnable && !IsRoiDifferent(pTask->input.pSurf, pTask->output.pSurf))

is much better.
But I won't insist of changing this if you like your approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is legacy. But I'm for the change, sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -2962,6 +2962,25 @@ mfxStatus VideoVPPHW::Close()
} // mfxStatus VideoVPPHW::Close()


mfxStatus VideoVPPHW::IsCopyPassThroughPreferred(bool &preferred) const
{
if (m_pCore->GetVAType() != MFX_HW_VAAPI || m_ioMode != D3D_TO_D3D)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this check mean that vaapi core is used?
I.e. cast on line 2979 wouldn't fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgonchar Yes, the cast must not fail. I don't like dropping the check, however. What can I do here, as there is no asserts in release and you think returning mfxStatus is ugly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, currently I see two different ways:

  1. Leave the current code, but return false instead of error if cast fails (which is supposed to be almost impossible situation). So we just silently hide the error (not actually so, because we can use trace macro to at least signal to stdout if traces are on)
  2. Move to references casting, then some upper layers should deal with possible exception (which is supposed to be almost impossible situation). So we loose information about place of error occurrence.

So both of these ways are definitely not much better than current approach. I will try to figure out better solution...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserts are enabled in release builds of master branch. They are switched off in builds of release branches. So, use assert if you feel it right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I want to be protected from some fearless code refactoring. So checking on master' release is just fine.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having virtual GetCmCopyStatus in core is not an option to avoid this cast which is ugly on its own?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe adding new virtual functions to CommonCORE is prohibited. That's why the cast was applied here.

@@ -908,6 +908,8 @@ namespace MfxHwVideoProcessing
mfxFrameSurface1 *pInputSurface,
mfxFrameSurface1 *pOutputSurface);

mfxStatus IsCopyPassThroughPreferred(bool &preferred) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this function:). Both prototype (+1 to @mgonchar) and how it named/what it does. It returns not deterministic result: "I check copy pass thru, maybe I like it maybe not - decide later". I would like to see function named useSOMETHING() with the obvious inclination.

To be honest, I got lost in CopyPassThrough name. What it actually mean? Copy with memcpy or CM?

@@ -2962,6 +2962,25 @@ mfxStatus VideoVPPHW::Close()
} // mfxStatus VideoVPPHW::Close()


mfxStatus VideoVPPHW::IsCopyPassThroughPreferred(bool &preferred) const
{
if (m_pCore->GetVAType() != MFX_HW_VAAPI || m_ioMode != D3D_TO_D3D)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserts are enabled in release builds of master branch. They are switched off in builds of release branches. So, use assert if you feel it right.

@@ -177,6 +177,8 @@ class VAAPIVideoCORE : public CommonCORE
// this function should not be virtual
mfxStatus SetCmCopyStatus(bool enable);

bool GetCmCopyStatus() const { return m_bCmCopy; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status in function name is misleading. Can we just have SetCmCopy(bool) and bool CmCopy()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -813,7 +813,7 @@ VAAPIVideoCORE::GetVAService(
} // mfxStatus VAAPIVideoCORE::GetVAService(...)

mfxStatus
VAAPIVideoCORE::SetCmCopyStatus(bool enable)
VAAPIVideoCORE::SetCmCopy(bool enable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe no sense for this function to return status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgonchar Is it possible to change mfxStatus CMEnabledCoreInterface::SetCmCopy(bool enable) to return void as well? Can it affect ABI of some plugins?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onabiull : please, comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wan't old plugins to remain functional, we need change interfaces by adding new ones. This would affect windows version in the first hand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onabiull : Does this apply to VAAPIVideoCORE or VideoCORE or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand Oleg correctly, CMEnabledCoreInterface is part of plugin API and so change of return value's type is prohibited.

So, rename virtual mfxStatus CMEnabledCoreInterface::SetCmCopyStatus(bool enable) to virtual mfxStatus CMEnabledCoreInterface::SetCmCopy(bool enable) is also incorrect and must be reverted.

{
if (m_pCore->GetVAType() != MFX_HW_VAAPI || m_ioMode != D3D_TO_D3D)
{
return true; // preferred unconditionally
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after function rename this comment is misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -3115,9 +3131,13 @@ mfxStatus VideoVPPHW::VppFrameCheck(
#endif
MFX_CHECK_STS(sts);

bool useCopyPassThrough =
(m_config.m_bCopyPassThroughEnable && !IsRoiDifferent(pTask->input.pSurf, pTask->output.pSurf))?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you don't want to move this condition to UseCopyPassThrough() as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -813,7 +813,7 @@ VAAPIVideoCORE::GetVAService(
} // mfxStatus VAAPIVideoCORE::GetVAService(...)

mfxStatus
VAAPIVideoCORE::SetCmCopyStatus(bool enable)
VAAPIVideoCORE::SetCmCopy(bool enable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onabiull : please, comment.

// This can't be done in ConfigureExecuteParams() because CmCopy status is set later.
const VAAPIVideoCORE *vaapiCore = dynamic_cast<VAAPIVideoCORE*>(m_pCore);
assert(vaapiCore);
return vaapiCore->CmCopy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you know, I am not sure I like this code. I would probably go with just:

const VAAPIVideoCORE *vaapiCore = dynamic_cast<VAAPIVideoCORE*>(m_pCore);
return (vaapiCore)? vaapiCore->CmCopy(): false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a huge "Can't happen!" and we are ignoring it silently, aren't we? Why not add
if(!vaapiCore) MFX_STS_TRACE(); at least?

@@ -2962,6 +2962,28 @@ mfxStatus VideoVPPHW::Close()
} // mfxStatus VideoVPPHW::Close()


bool VideoVPPHW::UseCopyPassThrough(const DdiTask *pTask) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of the function should probably be: UseCmCopyPassThrough(), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan was to hide mere presence of Cm. Why may a user of CopyPassThrought be interested in what is used inside? One just want fastest version, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it seems that this function implies that CM is going to be used. At least that's what I think looking into last line in its code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I got it after offline discussion. Under copy pass through we understand any mem copy operation without VP algorithms. This can be map+memcpy or cmcopy. In different modes we prefer different copy type.

@@ -813,7 +813,7 @@ VAAPIVideoCORE::GetVAService(
} // mfxStatus VAAPIVideoCORE::GetVAService(...)

mfxStatus
VAAPIVideoCORE::SetCmCopyStatus(bool enable)
VAAPIVideoCORE::SetCmCopy(bool enable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onabiull : Does this apply to VAAPIVideoCORE or VideoCORE or both?

@@ -2962,6 +2962,28 @@ mfxStatus VideoVPPHW::Close()
} // mfxStatus VideoVPPHW::Close()


bool VideoVPPHW::UseCopyPassThrough(const DdiTask *pTask) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I got it after offline discussion. Under copy pass through we understand any mem copy operation without VP algorithms. This can be map+memcpy or cmcopy. In different modes we prefer different copy type.

// for CM availability to do fallback to VPP if there is no CM.
// This can't be done in ConfigureExecuteParams() because CmCopy status is set later.
const VAAPIVideoCORE *vaapiCore = dynamic_cast<VAAPIVideoCORE*>(m_pCore);
assert(vaapiCore);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you can use following macro to simplify code + use assert + use traces:

MFX_CHECK_WITH_ASSERT(vaapiCore, false);

return vaapiCore->CmCopy();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

@Alexandr-Konovalov Alexandr-Konovalov force-pushed the copy-pass-through branch 2 times, most recently from d742fa8 to c5495f7 Compare March 20, 2019 07:27
@dvrogozh dvrogozh added the pr-ready Pull request is ready for merge label Mar 21, 2019
@onabiull onabiull merged commit 5d89dc0 into Intel-Media-SDK:master Mar 21, 2019
@Alexandr-Konovalov Alexandr-Konovalov deleted the copy-pass-through branch March 21, 2019 15:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-ready Pull request is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants